package cn.crm.spring.exception;

import org.apache.shiro.authz.UnauthenticatedException;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**
 * 全局异常处理
 */

@ControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(UnauthorizedException.class)
    public ModelAndView unauthorizedExceptionHandler(
            HttpServletRequest request, ModelAndView mv, UnauthenticatedException e){
        mv.setViewName("403");
        mv.addObject("exception",e);
        mv.addObject("url",request.getRequestURL());
        return mv;
    }
}
